import * as THREE from "three";

export class Particle {
    position: THREE.Vector3;
    velocity: THREE.Vector3;
    angleVolecity: number;
    angle: number;
    color: THREE.Vector3;
    alpha: number;
    alive: boolean;
    age: number;
    size: number;
    life: number;
    constructor(position: THREE.Vector3, velocity: THREE.Vector3, life: number, angleVolecity = 0) {
        this.position = position.clone();
        this.velocity = velocity.clone();
        this.life = life;
        this.age = 0;
        this.alive = true;
        this.color = new THREE.Vector3(1, 1, 1);
        this.angleVolecity = angleVolecity;
        this.angle = 0;
        this.alpha = 1;
        this.size = 1;
    }

    update(deltaTime: number) {
        this.age += deltaTime;
        this.position.addScaledVector(this.velocity, deltaTime);
        this.angle += this.angleVolecity * deltaTime;

        if (this.isDead()) {
            this.alive = false;
        }
    }

    reset(position: THREE.Vector3, velocity: THREE.Vector3, life: number, angle = 0, size = 1) {
        this.position.copy(position);
        this.velocity.copy(velocity);
        this.life = life;
        this.angle = angle;
        this.size = size;
        this.age = 0;
        this.alive = true;
    }

    isDead() {
        return this.age >= this.life;
    }
}